package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author huangxin
 * @description
 * @date 2020/12/2
 */
@Service
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierDao supplierDao;


    @Override
    public PageInfo<Supplier> getSuppliersByPageAndCondition(String supplierName) {
        List<Supplier> supplierList = supplierDao.queryAllSuppliersByCondition(supplierName);
        return new PageInfo<>(supplierList);
    }

    @Override
    public void saveSupplier(Supplier supplier) {
        supplierDao.saveSupplier(supplier);
    }

    @Override
    public void updateSupplierById(Supplier supplier) {
        supplierDao.updateSupplierById(supplier);
    }

    @Override
    public void deleteSuppliersBatch(String ids) {
        String[] split = ids.split(",");
        List<String> idList = Arrays.stream(split).collect(Collectors.toList());
        supplierDao.deleteSuppliersBatch(idList);
    }

    @Override
    public List<Map<String, Object>> getAllSuppliers() {
        return supplierDao.getAllSuppliers();
    }
}
